<template>
  <div class="app-container">
    <div id="app1" style="heigth: 50px; width: 100%">
      <form-create
        v-model="fApi"
        :rule="rule"
        :option="option"
        :value.sync="value"
      ></form-create>
    </div>
    <el-popover
      placement="bottom-end"
      trigger="click"
      class="m-l-10"
      v-model="popoverShow"
    >
      <os-draggable
        v-model="showFieldKeys"
        :data="selectorFields"
      ></os-draggable>
      <el-button
        slot="reference"
        size="small"
        type="primary"
        plain
        icon="el-icon-setting"
      ></el-button>
    </el-popover>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column fixed prop="date" label="日期" width="150">
      </el-table-column>
      <el-table-column prop="name" label="姓名" width="120"> </el-table-column>
      <el-table-column prop="province" label="省份" width="120">
      </el-table-column>
      <el-table-column prop="city" label="市区" width="120"> </el-table-column>
      <el-table-column prop="zip" label="邮编" width="120"> </el-table-column>
      <el-table-column prop="address" label="地址"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row)" type="text" size="small"
            >查看</el-button
          >
          <el-button type="text" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="10"
        layout="total, sizes, prev, pager, next, jumper"
        :total="400"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
// import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import formCreate from '@form-create/element-ui'
export default {
  components: { formCreate: formCreate.$form() },
  methods: {
    handleClick (row) {
      console.log(row)
    },
    getList () {
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
    }
  },

  data () {
    return {
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20
      },
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        province: '上海',
        city: '普陀区',
        address: '上海市普陀区金沙江路 1518 弄',
        zip: 200333
      }, {
        date: '2016-05-04',
        name: '王小虎',
        province: '上海',
        city: '普陀区',
        address: '上海市普陀区金沙江路 1517 弄',
        zip: 200333
      }, {
        date: '2016-05-01',
        name: '王小虎',
        province: '上海',
        city: '普陀区',
        address: '上海市普陀区金沙江路 1519 弄',
        zip: 200333
      }, {
        date: '2016-05-03',
        name: '王小虎',
        province: '上海',
        city: '普陀区',
        address: '上海市普陀区金沙江路 1516 弄',
        zip: 200333
      }],
      // 初始化draggable
      popoverShow: false,
      showFieldKeys: [{ key: 'date', label: '日期', checked: true }, { key: 'province', label: '省份', checked: true }],
      selectorFields: [
        { key: 'date', label: '日期', checked: false }, { key: 'name', label: '姓名', checked: true }, { key: 'province', label: '省份', checked: false }
      ],
      // 实例对象
      fApi: {},
      // 表单数据
      value: {},
      // 表单生成规则
      rule: [
        {
          type: 'input',
          field: 'goods_name',
          title: '商品名称'
        },
        {
          type: 'datePicker',
          field: 'created_at',
          title: '创建时间'
        }
      ],
      // 组件参数配置
      option: {
        // 表单提交事件
        onSubmit: function (formData) {
          alert(JSON.stringify(formData))
        }
      }
    }
  }
}
</script>
